package com.hyg.lib_music.ui.activity;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hyg.lib_base.mainUtils.StatusBarUtil;
import com.hyg.lib_common.Base.BaseActivity;
import com.hyg.lib_common.DataModel.EventBusMessage;
import com.hyg.lib_music.R;
import com.hyg.lib_music.adapter.MusicTesttingAnswerAdapter;
import com.hyg.lib_common.DataModel.testting.TesttingAnswer;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.util.ArrayList;

public class TesttingTizhiActivity extends BaseActivity {
    ArrayList<TesttingAnswer> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_music_testting_tizhi);
        StatusBarUtil.setStatusBar(1, this, getResources().getColor(R.color.white), 60, null, null, true);
        init();
    }

    public void init() {
        initData();
        initView();
    }

    public void initData() {
//        EventBus.getDefault().register(this);
        list = new ArrayList<>();
        String[] answer = getResources().getStringArray(R.array.music_tizhi_answer);
        for (String string : answer) {
            list.add(new TesttingAnswer(string, false));
        }
    }


    public void initView() {
        ImageView backBtn = findViewById(R.id.back);
        TextView titleTv = findViewById(R.id.tv_title);
        TextView infoTv = findViewById(R.id.tv_title_more);

        titleTv.setText("体质辨识问卷");
        infoTv.setText("问卷介绍");
        infoTv.setVisibility(View.VISIBLE);
        RecyclerView answerRcv = findViewById(R.id.rcv_answer);
        GridLayoutManager layoutManager = new GridLayoutManager(this, 3);
        MusicTesttingAnswerAdapter adapter = new MusicTesttingAnswerAdapter(this, list);
        answerRcv.setLayoutManager(layoutManager);
        answerRcv.setAdapter(adapter);

        infoTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(TesttingTizhiActivity.this, TesttingIntroActivity.class);
                intent.putExtra("type", "1");
                startActivity(intent);
            }
        });
        backBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }


    public void onNext(View view) {
        Intent intent=new Intent(this, TesttingTizhi1Activity.class);
//        intent.putStringArrayListExtra(, )
        intent.putParcelableArrayListExtra("list",list);
        startActivity(intent);
    }


    @Subscribe
    public void onEvent(EventBusMessage message) {
        //接收以及处理数据
        if(message.getmessage().equals("testTZfinish")){
            finish();
        }
    }

    @Override
    public void finish() {
        super.finish();
        EventBus.getDefault().unregister(this);
    }
}